package dungeon;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import basicPackage.Coordinate;
import basicPackage.Direction;
import basicPackage.Temperature;


/**
 * A class collecting test for the class of squares.
 * 
 * @author Laurens Vanderstraeten
 *
 */
public class DungeonTest {
        
        @BeforeClass
        public static void setUpBeforeClass() throws Exception {
                dungeon11squares2inhSlip= new Level<NormalSquare>(new Coordinate(15,1,0));
                coordinate1dungeon11squares2inhSlip = new Coordinate(1,1,0);
                square1dungeon11squares2inhSlip = new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false);
                dungeon11squares2inhSlip.placeSquare(coordinate1dungeon11squares2inhSlip, square1dungeon11squares2inhSlip);
                dungeon11squares2inhSlip.placeSquare(new Coordinate(2,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(3,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(4,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(5,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(6,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(7,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(8,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(9,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(10,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), true));
                dungeon11squares2inhSlip.placeSquare(new Coordinate(11,1,0), new NormalSquare(new Temperature(40), new BigDecimal("50.00"), true));

        }
        
        private static Level<NormalSquare> dungeon11squares2inhSlip;
        private static NormalSquare square1dungeon11squares2inhSlip;
        private static Coordinate coordinate1dungeon11squares2inhSlip;
        
        @Before
        public void setUp() throws Exception {
                dungeonMaxCoordX3Y5Z7 = new Level<NormalSquare>(new Coordinate(99,99,0));
        }

        private SquareDungeon<NormalSquare> dungeonMaxCoordX3Y5Z7;
        
        @Test
        public void Constructor_LegalCase() throws Exception{
                Coordinate coordinate = new Coordinate(1,2,0);
                Level<NormalSquare> SquareDungeon = new Level<NormalSquare>(coordinate);
                assertEquals(SquareDungeon.getMaxCoordinate(), coordinate);
        }
        
        @SuppressWarnings("unused")
        @Test (expected=IllegalArgumentException.class)
        public void Constructor_NonEffective() throws Exception{
        	Level<NormalSquare> SquareDungeon = new Level<NormalSquare>(null);
        }
        
        @SuppressWarnings("unused")
        @Test (expected=IllegalArgumentException.class)
        public void Constructor_NegativeCoordinate() throws Exception{
                Coordinate coordinate = new Coordinate(1,-2,0);
                Level<NormalSquare> SquareDungeon = new Level<NormalSquare>(coordinate);
        }
        
        @Test
        public void setMaxSquareCoordinate_LegalCase() throws Exception{
                Coordinate coordinate = new Coordinate(100,100,0);
                dungeonMaxCoordX3Y5Z7.setMaxCoordinate(coordinate);
                assertEquals(dungeonMaxCoordX3Y5Z7.getMaxCoordinate(), coordinate);
        }
        
        @Test (expected=IllegalArgumentException.class)
        public void setMaxSquareCoordinate_Ineffective() throws Exception{
                dungeonMaxCoordX3Y5Z7.setMaxCoordinate(null);
        }
        
        @Test (expected=IllegalArgumentException.class)
        public void setMaxSquareCoordinate_Negative() throws Exception{
                Coordinate coordinate = new Coordinate(4,-5,0);
                dungeonMaxCoordX3Y5Z7.setMaxCoordinate(coordinate);
        }
        
        @Test (expected=IllegalArgumentException.class)
        public void setMaxSquareCoordinate_Smaller() throws Exception{
                Coordinate coordinate = new Coordinate(2,5,0);
                dungeonMaxCoordX3Y5Z7.setMaxCoordinate(coordinate);
        }
        
        @Test
        public void getNbSquares_LegalCase(){
                assertTrue(dungeon11squares2inhSlip.getNbSquares()==11);
        }
        
        @Test
        public void getNbInherentlySlipperySquares_LegalCase() {
                assertTrue(dungeon11squares2inhSlip.getNbInherentlySlipperySquares()==2);
        }
        
        @Test
        public void getSquare_LegalCase() throws Exception{
                assertEquals(dungeon11squares2inhSlip.getSquare(coordinate1dungeon11squares2inhSlip), square1dungeon11squares2inhSlip);
        }
        
        @Test
        public void placeSquare_LegalCase() throws Exception{
                Coordinate coordinate1 = new Coordinate(1,2,0);
                Coordinate coordinate2 = new Coordinate(1,3,0);
                NormalSquare square1 = new NormalSquare(new Temperature(40), new BigDecimal("50.00"), false);
                NormalSquare square2 = new NormalSquare(new Temperature(40), new BigDecimal("60.00"), false);
                dungeonMaxCoordX3Y5Z7.placeSquare(coordinate1, square1);
                dungeonMaxCoordX3Y5Z7.placeSquare(coordinate2, square2);
                assertEquals(dungeonMaxCoordX3Y5Z7.getSquare(coordinate1), square1);
                assertEquals(dungeonMaxCoordX3Y5Z7.getSquare(coordinate2), square2);
                assertEquals(square1.getBorderingSquare(Direction.NORTH), square2);
        }
        
        @Test
        public void containsCoordinate_LegalCase(){
                assertTrue(dungeon11squares2inhSlip.containsElementCoordinate(coordinate1dungeon11squares2inhSlip));
        }
}
